/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
 */
/*
 * NewTest.java
 *
 * Created on January 8, 2003, 1:46 PM
 */

package tests.jd.crypt;

import java.math.*;
import java.security.*;
import java.security.interfaces.*;
import java.security.spec.*;

import javax.crypto.*;

import org.bouncycastle.util.test.*;
import org.bouncycastle.util.encoders.Hex;

import org.bouncycastle.jce.provider.BouncyCastleProvider;


/**
 *
 * @author  jdepons
 */
public class NewTest {
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
        
        java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        
        
        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(
        new BigInteger("0100000000000000000000000000000000bba2d15dbb303c8a21c5ebbcbae52b7125087920dd7cdf358ea119fd66fb064012ec8ce692f0a0b8e8321b041acd40b7", 16),
        new BigInteger("03", 16));
        
        RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(
        new BigInteger("0100000000000000000000000000000000bba2d15dbb303c8a21c5ebbcbae52b7125087920dd7cdf358ea119fd66fb064012ec8ce692f0a0b8e8321b041acd40b7", 16),
        new BigInteger("2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac9f0783a49dd5f6c5af651f4c9d0dc9281c96a3f16a85f9572d7cc3f2d0f25a9dbf1149e4cdc32273faadd3fda5dcda7", 16));
                        
        
        byte[] input = "J".getBytes();
        
        KeyFactory fact = KeyFactory.getInstance("RSA", "BC");
        
        PrivateKey  privKey = fact.generatePrivate(privKeySpec);
        PublicKey   pubKey = fact.generatePublic(pubKeySpec);
        
        Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
        
        c.init(Cipher.ENCRYPT_MODE, pubKey, new SecureRandom());
        
        System.out.println("original = " + new String(input));
        
        byte[] out = c.doFinal(input);
        
        System.out.println("after encrypt = " + new String(out));
        
        c.init(Cipher.DECRYPT_MODE, privKey);
        
        out = c.doFinal(out);
        
        System.out.println("after decrypt = " + new String(out));
        
    }
    
}
